package com.demo.thread.sync;

/**
 * @author : YU.TAN
 * @date : 2021/11/3 18:09
 */
public class SynchronizedDemoA {
    public static void main(String[] args) {

        SyncNum syncNum=new SyncNum();

        syncNum.setNumber(100);
        syncNum.setFlag(true);



        Thread threadA=new Thread(new Runnable() {
            @Override
            public void run() {
                while (syncNum.getFlag()){
                    int blood = syncNum.decreaseBlood();
                    if (blood<=0){
                        System.out.println("A完成！");
                    }
                }
            }
        }
        );

        Thread threadB=new Thread(new Runnable() {
            @Override
            public void run() {
                while (syncNum.getFlag()){
                    int blood = syncNum.decreaseBlood();
                    if (blood<=0){
                        System.out.println("B完成！");
                    }
                }
            }
        }
        );

        threadA.start();
        threadB.start();
    }
}
